<?php

require_once("ui.php");
require_once("report.template.php");

class ToolingTab {
		
	private function printDefaultlyBlankSelect($id, $items) {
		$previousValue = getOriginalPost($id);		
		$optionsInfo = array();
		$defaultOptionValue;
		
		if (($previousValue == null) || ($previousValue == -1)) {			
			$optionInfo['value'] = '-1';
			$optionInfo['description'] = "";
			
			array_push($optionsInfo, $optionInfo);
			$defaultOptionValue = $optionInfo['value'];
		} else {
			$defaultOptionValue = $previousValue;
		}
		
		foreach ($items as $i => $item) {
			$optionInfo['value'] = $item['Id'];
			$optionInfo['description'] = $item['Description'];
			
			array_push($optionsInfo, $optionInfo);				
		}								
	
		printSelect($id, null, null, $optionsInfo, $defaultOptionValue, "");
	}
		
	private function printMissingIntentArea() {
		
		$previousValue = getOriginalPost(INPUT_MISSING_INTENT_TEXT_AREA);
		$previousValue = ($previousValue == null) ? "" : $previousValue;
		
		echo '<textarea rows="2" cols="20" id="' . INPUT_PROBLEM_TEXT_AREA . '"
			name="' . INPUT_MISSING_INTENT_TEXT_AREA . '">' . $previousValue . '</textarea>';
	}
	
	public function printTabContent() {
		
		global $db;		
		
		$sql = "SELECT Id, Description FROM `debugging_Intents` ORDER BY Description";
		$db->sql_query($sql);
		$intents = $db->sql_fetchall();
		
		global $loggedInUser;
?>
				<div class="reportTab" id="generalTab">
					<table>
						<tbody>
							<tr>
								<td>Debugging intent:<div class="help" onmouseover="popup('What you wanted to achieve by using the debugging tools in this case.');"></div>
								<?php
									$this->printDefaultlyBlankSelect(INPUT_DEBUGGING_INTENTS, $intents);
								?>
								</td>
							</tr>
							<tr>
								<td>You are welcomed to fill in any missing intent or tool that is not in the menu:<br>
									<?php
										$this->printMissingIntentArea();
									?>
								</td>
							</tr>
						</tbody>
					</table>
				</div>
<?php 	
	}
}
?>
